// pages/idPwd/idPwd.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    oldPwd: "",
    newPwd: "",
    err: true,
    text: "由6-21字母和数字组成，不能是纯数字或纯英文"
  },
  oldBlur(e){
    this.setData({
      oldPwd: e.detail.value
    })
  },
  newBlur(e){
    this.setData({
      newPwd: e.detail.value
    })
  },
  onSubmit(){
    let that = this;
    //验证新密码是否合法
    let regExp = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/;
    if (!regExp.test(that.data.newPwd) || !regExp.test(that.data.oldPwd)) {
      that.setData({
        text: "密码不合法，请重新输入"
      },function(){
        setTimeout(function(){
          that.setData({
            text: "由6-21字母和数字组成，不能是纯数字或纯英文"
          })
        },1500)
      })
      return
    }

    //提示框 
    if (that.data.oldPwd && that.data.newPwd){
      wx.showToast({
        title: '修改成功',
        duration: 1500,
        mask: true
      })
      //跳转页面
      setTimeout(function(){
        wx.switchTab({
          url: '/pages/index/index',
        })
      },1500)
    }else{
      wx.showToast({
        title: '修改失败',
        icon: 'none',
        duration: 1500,
        mask: true
      })
    }
  }

  
})